import { data } from 'jquery';
import { Component, Input, OnInit } from '@angular/core';
import { ModalController } from '@ionic/angular';

@Component({
  selector: 'app-fw-picker',
  templateUrl: './fw-picker.component.html',
  styleUrls: ['./fw-picker.component.scss'],
})
export class FwPickerComponent implements OnInit {
  @Input() item: any;
  tempItem: any;
  result: any;
  constructor(
    public modalController: ModalController,

  ) { }

  ngOnInit() {
    this.tempItem = JSON.parse(JSON.stringify(this.item));
    if (this.tempItem.formType === 'pickerSelectDate' || this.tempItem.formType === 'chooseHours') {
      this.tempItem.data = this.tempItem.children;
    }
    // 一级
    if (this.tempItem.data) {
      this.tempItem.value = [this.tempItem.data[0].value];
      this.result = [this.tempItem.data[0]];
    }
    // 二级
    if (this.tempItem.data && this.tempItem.data[0].children && this.tempItem.data[0].children[0]) {
      this.tempItem.value = [this.tempItem.data[0].value, this.tempItem.data[0].children[0].value];
      this.result = [this.tempItem.data[0], this.tempItem.data[0].children[0]];
      // 三级
      if (this.tempItem.data[0].children[0].children && this.tempItem.data[0].children[0].children[0]) {
        this.tempItem.value = [this.tempItem.data[0].value,
        this.tempItem.data[0].children[0].value,
        this.tempItem.data[0].children[0].children[0].value];

        this.result = [this.tempItem.data[0],
         this.tempItem.data[0].children[0],
         this.tempItem.data[0].children[0].children[0]];
      }
    }
    this.clickOnPickerSelect(0)
  }

  clickOnPickerSelect(event){}
  cancel() {
    this.modalController.dismiss();

  }
  sure() {
    Object.assign(this.item, this.tempItem);
    this.modalController.dismiss({data: {result: this.result, item: this.item} } );

  }
  // <!-- 行业 区域 单选 双联picker-->
  pickerSelect(result, item) {
    this.result = result;
    // if (result && result.length && Array.isArray(result)) {
    //   if (result.length === 1) {
    //     item.value = result[0].value;
    //     item.showValue = `${result[0].label}`;
    //   } else if (result.length === 2) {
    //     item.value = result[1].value;
    //     item.showValue = `${result[0].label} ${result[1].label}`;
    //     if (item.minSize && item.minSize === 1) {
    //       item.showValue = `${result[1].label}`;
    //     }
    //     if (item.formType === "pickerSelectDate") {
    //       item.value = `${result[0].value} ${result[1].value}`;
    //       item.showValue = `${result[0].label} ${result[1].label}`;
    //     }

    //   } else {
    //     item.value = result[2].value;
    //     item.showValue = `${result[0].label} ${result[1].label} ${result[2].label}`;
    //     if (item.minSize && item.minSize === 1) {
    //       item.showValue = `${result[2].label}`;
    //     }
    //   }

    // }
  }
}
